package edu.ruc.cluster.print;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.util.Scanner;
import javax.swing.JLabel;

/**
 * 
 * Class Description：
 * Scan input stream
 * put scanned character on JLabel
 * @date 2012-12-30
 * @version 1.0
 */
public class LabelLogAppender extends LogAppender {

    private JLabel label;

    /**
     * default constructor
     * @param recorder name, output log information from label will be put to JLabel component
     * @throws IOException 
     */
    public LabelLogAppender(JLabel label) throws IOException {
        super("label");
        this.label = label;
    }

    @Override
    public void run() {
        // scan input stream reader
        Scanner scanner = new Scanner(reader);
        // put scanned character on label
        while (scanner.hasNextLine()) {
            try {
                
                Thread.sleep(100);
                String line = scanner.nextLine();
                label.setText(line);
                line = null;
                 } catch (Exception ex) {
                //do not deal exception
            }
        }
    }
}
